﻿using System.Collections.Generic;
using Rhino.Mocks;
using VirtualDeveloper;
using Xunit;

namespace UnitTest
{
    public class WorkingDeveloperUnitTest
    {
        private readonly IFileAdapter fileAdapterMock;
        private readonly MockRepository mockRepository = new MockRepository();

        public WorkingDeveloperUnitTest()
        {
            fileAdapterMock = mockRepository.StrictMock<IFileAdapter>();
        }

        [Fact]
        public void Ensure_public_ctor()
        {
            Assert.NotNull(new WorkingDeveloper(@"d:\Sample"));
        }


        [Fact]
        public void Developer_big_changes()
        {
            fileAdapterMock.Expect(x => x.GetFiles(@"d:\sample", "*.txt")).Return(new List<string> { "1.txt" });
            const string inputCode = @"hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world";
            fileAdapterMock.Expect(x => x.ReadAllText("1.txt")).Return(inputCode);

            fileAdapterMock.Expect(x => x.SaveToFile(Arg<string>.Is.Equal("1.txt"), Arg<string>.Is.NotEqual(inputCode)));
            mockRepository.ReplayAll();
            var workingDev = new WorkingDeveloper(@"d:\sample", "*.txt", fileAdapterMock);
            workingDev.BigChanges();
            mockRepository.VerifyAll();
        }

        [Fact]
        public void Developer_make_standard_changes()
        {
            fileAdapterMock.Expect(x => x.GetFiles(@"d:\sample", "*.txt")).Return(new List<string> { "1.txt", "2.txt", "3.txt" });
            const string inputCode = @"hello world
toto
titi
titi
titi
titi
titi
titi
tata";
            
            fileAdapterMock
                .Expect(x => x.ReadAllText("2.txt"))
                .Return(inputCode);

            fileAdapterMock.Expect(x => x.SaveToFile(Arg<string>.Is.Equal("2.txt"), Arg<string>.Is.NotEqual(inputCode)));

            mockRepository.ReplayAll();
            var workdingDev = new WorkingDeveloper(@"d:\sample", "*.txt", fileAdapterMock);

            workdingDev.StandardChanges();
            mockRepository.VerifyAll();
        }

        [Fact]
        public void Developer_make_little_changes()
        {

            fileAdapterMock.Expect(x => x.GetFiles(@"d:\sample", "*.txt")).Return(new List<string> { "1.txt", "2.txt", "3.txt", "4.txt", "5.txt", "6.txt", "7.txt" });
            const string inputCode = @"hello world
hello toto
hello toto
hello toto
hello toto
hello toto
hello toto
hello toto
hello toto
hello toto
hello toto
hello toto
";
            fileAdapterMock
                .Expect(x => x.ReadAllText("6.txt"))
                .Return(inputCode);

            fileAdapterMock.Expect(x => x.SaveToFile(Arg<string>.Is.Equal("6.txt"), Arg<string>.Is.NotEqual(inputCode)));
            mockRepository.ReplayAll();

            var workingDev = new WorkingDeveloper(@"d:\sample", "*.txt", fileAdapterMock);

            workingDev.LittleChanges();

            mockRepository.VerifyAll();
        }
    }
}